// DP42 【模板】完全背包
// https://www.nowcoder.com/share/jump/8579736501701266908345

#include <iostream>
#include <vector>
using namespace std;

int n = 0, V = 0;

// int request1(vector<int>& v, vector<int>& w)
// {
//     vector<vector<int>> dp(n+1, vector<int>(V+1));

//     for (int i = 1; i<=n; ++i)
//     {
//         for (int j = 1; j<=V; ++j)
//         {
//             dp[i][j] = dp[i-1][j];
//             if (j >= v[i])
//                 dp[i][j] = max(dp[i][j], dp[i][j-v[i]] + w[i]);
//         }
//     }

//     return dp[n][V];
// }

int request1(vector<int>& v, vector<int>& w)
{
    vector<int> dp(V+1);

    for (int i = 1; i<=n; ++i)
    {
        for (int j = v[i]; j<=V; ++j)
        {
            dp[j] = max(dp[j], dp[j-v[i]] + w[i]);
        }
    }

    return dp[V];
}

// int request2(vector<int>& v, vector<int>& w)
// {
//     vector<vector<int>> dp(n+1, vector<int>(V+1));

//     for (int j = 1; j<=V; ++j)
//         dp[0][j] = -1;
    
//     for (int i = 1; i<=n; ++i)
//     {
//         for (int j = 1; j<=V; ++j)
//         {
//             dp[i][j] = dp[i-1][j];
//             if (j>=v[i] && dp[i][j-v[i]]!=-1)
//                 dp[i][j] = max(dp[i][j], dp[i][j-v[i]] + w[i]);
//         }
//     }

//     return dp[n][V] == -1 ? 0 : dp[n][V];
// }

int request2(vector<int>& v, vector<int>& w)
{
    vector<int> dp(V+1);

    for (int j = 1; j<=V; ++j)
        dp[j] = -1;
    
    for (int i = 1; i<=n; ++i)
    {
        for (int j = v[i]; j<=V; ++j)
        {
            if (dp[j-v[i]] != -1)
                dp[j] = max(dp[j], dp[j-v[i]] + w[i]);
        }
    }

    return dp[V] == -1 ? 0 : dp[V];
}

int main()
{
    cin >> n >> V;
    
    vector<int> v(n+1), w(n+1);

    for (int i = 1; i<=n; ++i)
        cin >> v[i] >> w[i];
    
    cout << request1(v, w) << endl;
    cout << request2(v, w) << endl;

    return 0;
}